package com.zang.blogz.strategy.context;

import com.zang.blogz.enmus.MarkdownTypeEnum;
import com.zang.blogz.entity.Article;
import com.zang.blogz.model.input.ro.ArticleReviseRO;
import com.zang.blogz.model.output.ImportArticleRO;
import com.zang.blogz.strategy.ArticleImportStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 文章导入策略上下文
 * @author ZVerify
 * @since 2022/10/13 18:50
 **/
@Service
public class ArticleImportStrategyContext {

    @Autowired
    private Map<String, ArticleImportStrategy> articleImportStrategyMap;


    /**
     * @param file 文件
     * @param type 文件类型
     * @return {@link Article} 导入的文章信息
     */
    public ArticleReviseRO importArticles(MultipartFile file, ImportArticleRO importArticleRO){

        return articleImportStrategyMap.get(MarkdownTypeEnum.getMarkDownType(importArticleRO.getType())).importArticles(file, importArticleRO);
    }

}
